package com.googlecode.transmutant.spring

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder 
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

class StepperBeanDefinitionParser extends AbstractBeanDefinitionParser{

	AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
		return parseStepperElement(element)
	}
	
	static AbstractBeanDefinition parseStepperElement(Element element) {
		BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(SpringStepper.class)
		def steps = element.getAttribute("steps")
		factory.addPropertyReference("stepsWrapper", steps)
		if(element.getAttribute("autorun").equals("true")) {
			factory.setInitMethodName("run")
		}
		if(element.hasAttribute("captures")) {
			String captures = element.getAttribute("captures")
			factory.addPropertyReference("captures", captures)
		}
		return factory.getBeanDefinition()
		
	}
}
